package com.lamer.console.common.api;

import lombok.*;

@Getter
@Setter
@ToString
public class ApiResult<T> {

    private int code;
    private String message;
    private T data;

    private ApiResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ApiResult<T> success(){
        return new ApiResult<>(ApiCode.SUCCESS.getCode(), ApiCode.SUCCESS.getMessage(), null);
    }

    public static <T> ApiResult<T> success(String message){
        return new ApiResult<>(ApiCode.SUCCESS.getCode(), message, null);
    }

    public static <T> ApiResult<T> success(T data){
        return new ApiResult<>(ApiCode.SUCCESS.getCode(), ApiCode.SUCCESS.getMessage(), data);
    }

    public static <T> ApiResult<T> success(String message, T data){
        return new ApiResult<>(ApiCode.SUCCESS.getCode(), message, data);
    }

    public static <T> ApiResult<T> failed() {
        return failed(ApiCode.FAILED);
    }

    public static <T> ApiResult<T> failed(ApiCode apiCode) {
        return new ApiResult<>(apiCode.getCode(), apiCode.getMessage(), null);
    }

    public static <T> ApiResult<T> failed(String message) {
        return new ApiResult<>(ApiCode.FAILED.getCode(), message, null);
    }

    public static <T> ApiResult<T> unauthorized(){
        return unauthorized(null);
    }

    public static <T> ApiResult<T> unauthorized(T data){
        return new ApiResult<>(ApiCode.UNAUTHORIZED.getCode(), ApiCode.UNAUTHORIZED.getMessage(), data);
    }

}
